package com.sch.study.concurrency.BlockQ;

import java.util.concurrent.BlockingQueue;

/**
 * User: hui_stone
 * Date: 2016/3/3 0003
 * Time: 上午 11:06
 */
public class Producer implements Runnable{

    private String username;
    private BlockingQueue<String> dataQueue;

    public Producer(String username, BlockingQueue<String> dataQueue) {
        this.username = username;
        this.dataQueue = dataQueue;
    }

    @Override
    public void run() {
        try {
            while(true){
                int productID  = (int)(Math.random()*1000); //产生0~999随机整数
                dataQueue.put(String.valueOf(productID));
                System.out.println(username + "已生产(" + productID + ")");
                Thread.sleep(500);
            }
        } catch (InterruptedException e1) {
            e1.printStackTrace();
        }
    }
}
